package com.example.mapper;

import com.example.pojo.*;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface TeacherSecondPageMapper {

    List<Student> loadScores(Integer teacherId);

  /*  @Update("update grades set subject_id=(select  subject_id from subjects where subject_name=#{newSubjectName}),score=#{score},semester=#{newSemester},usual_score=#{usualScore},midterm_score=#{midtermScore},final_score=#{finalScore},earn_credit=#{earnCredit} where student_id=#{studentId} and semester=#{semester} and subject_id=(select  subject_id from subjects where subject_name=#{subjectName})")
    void editScore(Score score);*/
  @Update("update grades set subject_id=(select  subject_id from subjects where subject_name=#{newSubjectName}),score=#{score},usual_score=#{usualScore},midterm_score=#{midtermScore},final_score=#{finalScore},earn_credit=#{earnCredit} where student_id=#{studentId}  and subject_id=(select  subject_id from subjects where subject_name=#{subjectName})")
  void editScore(Score score);

   /* @Delete("delete from grades where student_id=#{studentId} and semester=#{semester} and subject_id=(select  subject_id from subjects where subject_name=#{subjectName})")
    void deleteScore(Score score);*/
   @Delete("delete from grades where student_id=#{studentId}  and subject_id=(select  subject_id from subjects where subject_name=#{subjectName})")
   void deleteScore(Score score);

    Percentage inqueryPercentage(Score score);

    @Select("select credit from subjects where subject_name=#{newSubjectName}")
    Integer inqueryCredit(Score score);

    @Select("select count(1)>0 from grades where student_id=#{studentId} and subject_id=(select  subject_id from subjects where subject_name=#{newSubjectName})")
    boolean isExistScore(Score score);
}
